import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';

import 'expense_model.dart';

class HomeViewModel with ChangeNotifier {
  List<ExpenseModel> expenses = [];

  double _budget = 10000.00;

  addExpense(String title, double amount, String category) {
    var exp = ExpenseModel(
        title: title, amount: amount, date: DateTime.now(), category: category);

    expenses.add(exp);

    notifyListeners();
  }

  removeExpense(String id) {
    expenses.removeWhere((exp) => exp.id == id);

    notifyListeners();
  }

  void setBudget(double budget) {
    _budget = budget;

    notifyListeners();
  }

  double get budget {
    return _budget;
  }

  List<ExpenseModel> get recentExpenses {
    return expenses;
  }

  double get totalBalance {
    return _budget - totalExpenses;
  }

  double get totalExpenses {
    return expenses.fold(0, (sum, exp) => sum + exp.amount);
  }
}
